<!DOCTYPE html>
<html>
<head>
    <meta charset="utf8">
    <title></title>
</head>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<body>
<?php
$dsn="mysql:host=localhost;dbname=exam";
$db=new PDO($dsn,'root','');
$db->query('set names utf8');
$result=$db->query('select * from exam0');
$result->setFetchMode(PDO::FETCH_ASSOC);
?>
<div class="container">
    <div class="panel panel-success">
        <div class="panel-heading">
            <h3 class="panel-title" align="center">考试查询</h3>
        </div>
        <div class="panel-body">
            <table  class="table table-striped" >
                <fieldset>
                    <legend class="text-center">共有<?php echo $result->rowCount() ?>门课程可以考试，请根据各自班级准时去往各自考场</legend>
                    <thead>
                    <tr>
                        <th>考试科目</th>
                        <th>考试班级</th>
                        <th>考试时间</th>
                        <th>考试地点</th>
                        <th>监考老师</th>
                    </tr>
                    </thead>
                </fieldset>
                <tbody>
                <form method='post' action="">
                    <div>
                        <input type="submit" style="float: right" value="搜索">
                        <span style="float: right">&nbsp;&nbsp;&nbsp;</span>
                        <input type="text" style="float: right" name="selected">
                    </div>
                </form>
                    <?php
                    if (isset($_POST['selected'])){
                        $mohu=$db->prepare ("select * from exam0 where course like ?");
                        $cour=$_POST['selected'];
                        $mohu->execute(array("%$cour%"));
                        $mohu->setFetchMode(PDO::FETCH_ASSOC);
                        while($row=$mohu->fetch()){
                            echo "
                          <tr>
	                      <td>$row[course]</td>
	                      <td>$row[class]</td>
                          <td>$row[time]</td>
                          <td>$row[place]</td>
                          <td>$row[teacher]</td>
                         </tr>
                         ";
                            $name=$row['course'];
                        }
                    }
                    else{
                    while($row=$result->fetch()){
                        echo "
                          <tr>
	                      <td>$row[course]</td>
	                      <td>$row[class]</td>
                          <td>$row[time]</td>
                          <td>$row[place]</td>
                          <td>$row[teacher]</td>
                         </tr>
                         ";
                    }
                    }
                    ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
